package com.dengyin2000.javaeye.ordering.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.validator.NotNull;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Role;
import org.jboss.seam.annotations.Roles;

@Entity
@Name("snackShop")
@Roles({@Role(name="exampleSnackShop", scope=ScopeType.SESSION),@Role(name="selectedShop", scope=ScopeType.SESSION)})
@Table(name="snack_shop")
public class SnackShop implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1731657217956294873L;

	private Long id;
	private String name;
	private String address;
	private String telNo;
	private String memo;
	private Set<Dish> monDishes = new HashSet<Dish>();
	private Set<Dish> tuesDishes = new HashSet<Dish>();
	private Set<Dish> wedDishes = new HashSet<Dish>();
	private Set<Dish> thuDishes = new HashSet<Dish>();
	private Set<Dish> friDishes = new HashSet<Dish>();
	private Set<Dish> satDishes = new HashSet<Dish>();
	private Set<Dish> sunDishes = new HashSet<Dish>();
	@OneToMany(cascade=CascadeType.ALL, mappedBy="monId")
	public Set<Dish> getMonDishes() {
		return monDishes;
	}
	public void setMonDishes(Set<Dish> monDishes) {
		this.monDishes = monDishes;
	}
	@OneToMany(cascade=CascadeType.ALL, mappedBy="tuesId")
	public Set<Dish> getTuesDishes() {
		return tuesDishes;
	}
	public void setTuesDishes(Set<Dish> tuesDishes) {
		this.tuesDishes = tuesDishes;
	}
	@OneToMany(cascade=CascadeType.ALL, mappedBy="wedId")
	public Set<Dish> getWedDishes() {
		return wedDishes;
	}
	public void setWedDishes(Set<Dish> wedDishes) {
		this.wedDishes = wedDishes;
	}
	@OneToMany(cascade=CascadeType.ALL, mappedBy="thuId")
	public Set<Dish> getThuDishes() {
		return thuDishes;
	}
	public void setThuDishes(Set<Dish> thuDishes) {
		this.thuDishes = thuDishes;
	}
	@OneToMany(cascade=CascadeType.ALL, mappedBy="friId")
	public Set<Dish> getFriDishes() {
		return friDishes;
	}
	public void setFriDishes(Set<Dish> friDishes) {
		this.friDishes = friDishes;
	}
	@OneToMany(cascade=CascadeType.ALL, mappedBy="satId")
	public Set<Dish> getSatDishes() {
		return satDishes;
	}
	public void setSatDishes(Set<Dish> satDishes) {
		this.satDishes = satDishes;
	}
	@OneToMany(cascade=CascadeType.ALL, mappedBy="sunId")
	public Set<Dish> getSunDishes() {
		return sunDishes;
	}
	public void setSunDishes(Set<Dish> sunDishes) {
		this.sunDishes = sunDishes;
	}
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	@NotNull
	@Column(unique=true)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@NotNull
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	@NotNull
	@Column(name="tel_no")
	public String getTelNo() {
		return telNo;
	}
	public void setTelNo(String telNo) {
		this.telNo = telNo;
	}
	public String getMemo() {
		return memo;
	}
	public void setMemo(String memo) {
		this.memo = memo;
	}
	
	@Transient
	public List<Dish> getDishesForToday() {
		Calendar today = Calendar.getInstance();
		int i = today.get(Calendar.DAY_OF_WEEK);
		List<Dish> rt = new ArrayList<Dish>();
		switch (i) {
		case Calendar.MONDAY:
			rt.addAll(getMonDishes());
			break;
		case Calendar.TUESDAY:
			rt.addAll(getTuesDishes());
			break;
		case Calendar.WEDNESDAY:
			rt.addAll(getWedDishes());
			break;
		case Calendar.THURSDAY:
			rt.addAll(getThuDishes());
			break;
		case Calendar.FRIDAY:
			rt.addAll(getFriDishes());
			break;
		case Calendar.SATURDAY:
			rt.addAll(getSatDishes());
			break;
		case Calendar.SUNDAY:
			rt.addAll(getSunDishes());
			break;
		default:
			break;
		}
		return rt;
	}
	
}
